<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/bootstarp/css/bootstrap.min.css" /> 
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/public.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/custom.css" />
<style type="text/css">
.s_content{
	top: 0;
	left: 0;
	width: 100%;
}
</style>
</head>
<body>
<div class="s_content m_xwraps">
    <ul class="m_xmanage fix">
        <li class="on" handleStatus="-1"><a href="javascript:;">全部</a></li>
        <li class="answer" handleStatus="0"><a href="javascript:;">待回复</a></li>
        <li handleStatus="1"><a href="javascript:;">已处理</a></li>
    </ul>
    <div class="s_kh_tab">
        <div class="k_on">
            <div class="m_xnavs fix">
                <div class="line">
                    <span>关键字</span>
                    <p><input type="text" placeholder="输入姓名/邮箱/电话，支持模糊搜索" class="text" data-provide="typeahead" id="keyWord" maxlength="25" onblur="checkLength(this)"></p>
                </div>
                <div class="line" style="width:180px;">
                    <span>来源</span>
                    <div class="k_select">
                      <span>所有渠道</span>
                      <div class="k_selectBox">
                        <ul>
                          <li source="">所有渠道</li>
                          <li source="1">微博</li>
                          <li source="2">活动</li>
                          <li source="3">智能营销活动</li>
                        </ul>
                      </div>
                      <span class="k_dropImg" style="padding-top: 14px;"><img src="<%=path%>/bc/images/dropDown.png"/></span>
                    </div>
                </div> 
                <div class="line">   
                    <a href="javascript:;" class="search"><img src="<%=path%>/bc/images/search.png" /></a>
                </div>
            </div>
            <div class="m_xdatuma" style="margin:0;">
                <div class="m_xconent all">
                    <ul class="m_xabout m_xsource fix">
                    </ul>
                    
                    <div style="clear: both;height: 0.001px"></div>
                    
                    <div class="m_xpages">
                        <div class="mian">
                            <span>显示个数</span>
                            <select><option>12</option><option>24</option><option>48</option></select>
                            <span>共80条</span>
                            <span>1/4页</span>
                            <a href="javascript:;" class="prev">上一页</a>
                            <a href="javascript:;" class="next">下一页</a>
                            <span>前往</span>
                            <input type="text" value="1" class="text">
                            <span>页</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>        
</div>
</body>
<script type="text/javascript" src="<%=path%>/bc/bootstarp/js/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.js"></script>
<script type="text/javascript" src="<%=path%>/js/page.js"></script>
<script type="text/javascript" src="<%=path%>/bm/js/lengthlimit.js"></script>
<script type="text/javascript">
var startIndex = 0;
var pageSize = 12;
var keyWord = "";		//搜索关键字
var handleStatus = -1;	//处理状态
var source = null;
var currentPage = 1;
var pageCount = 0;

var customerId = 0;	//客户id
var actionId = 0;	//客户行为id
var writeOffId = 0;	//核销id

$(function(){
	init();
	
	/*聊天点击开始*/
	$(document).on("click",".J_xdialogue",function(){
		//初始化数据，全部设置0
		top.customerId = 0;
		top.actionId = 0;
		top.clueWeiboId = 0;
		top.writeOffId = 0;
		
		customerId = $(this).attr("customerId");
		actionId = $(this).attr("actionId");
		writeOffId = $(this).attr("writeOffId");
		top.customerId = customerId;
		top.actionId = actionId;
		top.writeOffId = writeOffId;
		
<%-- 		$.post("<%=path%>/api/customer_action/customerChatView",function(data){ --%>
			var d = top.dialog({
				fixed: true,
				zIndex: 10000,
				padding:0,
				width:1172,
				height:568,
				title:'沟通记录',
// 				content:data,
				url:"<%=path%>/api/customer_action/customerChatView",
				cancelDisplay: false,
				cancel: function () {
					if(top.customerChatChange == 1){
						init();
						top.customerChatChange = 0;
					}
					top.customerId = 0;
					top.actionId = 0;
					top.clueWeiboId = 0;
					top.writeOffId = 0;
					return true;
				}
			});
			d.showModal();
// 		})
	});
	/*聊天点击结束*/
	
	$('.k_select').on('click',function(){
		$(this).toggleClass('selectState');
      	if(!$(this).hasClass('selectState')){
        	$('.k_select').removeClass('selectState');
        	$(this).find('img').attr('src','<%=path%>/bc/images/dropDown.png');
      	}else{
        	$(this).find('img').attr('src','<%=path%>/bc/images/dropUp.png');
      	}
    });
	
	$(".k_select>.k_selectBox>ul>li").on('click',function(){
		$(".k_select>span:eq(0)").text($(this).text());
		source = $(this).attr("source");
	});
	
	$('.m_xmanage>li').click(function(){
        $(this).addClass('on').siblings().removeClass();
        handleStatus = $(this).attr("handleStatus");
        currentPage = 1;
		startIndex = 0;
       	init();
    });
	
	/* 查询按钮点击开始 */
	$(".search").click(function(){
		keyWord = $("#keyWord").val();
		currentPage = 1;
		startIndex = 0;
		init();
	});
	/* 查询按钮点击结束 */
	
	
	//zhiwen
$('#keyWord').typeahead({
	 source: function (query, process) {
		
        var parameter ={name:query};
        $.post("${pageContext.request.contextPath}/api/customer_action/searchName", parameter, function (data) {
           //赵鑫把值写成下面这样的就好了
           var objarray =new Array("Deluxe Bicycle", "Super Deluxe Trampoline", "Super Duper Scooter");
           process(objarray);//这句是关键
//         	if ((data.name)!=null&&(data.name)!="") {
// 				console.log(data.name);
// 			}
        });
    }
});
/* -------------------------------------- */
	
	//联想搜索名字	
	var name = "张";
	$.post("<%=path%>/api/customer_action/searchName",{name:name},function(data){
		
	},"json");
});

function init(){
	$.post('<%=path%>/api/customer_action/actionList',
			{"startIndex":startIndex,"pageSize":pageSize,"keyWord":keyWord,"handleStatus":handleStatus,"source":source},
	function(data){
		
		data = JSON.parse(data);
		
		if(data.noHandleCount>0 && data.noHandleCount < 100)
			$(".answer>a").append("<i>"+data.noHandleCount+"</i>");
		else if(data.noHandleCount >= 100){
			$(".answer>a").append("<i>99+</i>");
		}
		
		setList(data.actionList);
		
		page(data.totalCount);
		
		parent.changeFrameHeight();
	});
}

function setList(actionList){
	var li = "";
	for(var i = 0; i < actionList.length; i++){
		var a = actionList[i];
		var avatar = a.avatar;
		if(avatar == undefined){
			avatar = "";
		}
		li += '<li class="fix"><div class="box"><div class="satell"><div class="bore"><p><span>最近行为: </span><em class="red">'+a.content+'</em></p><p class="gray"><span>最近消费: </span>'+(a.lastCostTimeStr==null?"无":a.lastCostTimeStr)+'</p></div><div class="pics"><strong><img src="'+((avatar == null || avatar == undefined || avatar == "") ? "<%=path%>/images/000head_pic.png" : avatar)+'" /></strong><div class="right"><a href="<%=path%>/api/custome/customerInfo?customerID='+a.customerId+'"'+' class="name">'+a.name+'</a><div class="nvs"><b customerId="'+a.customerId+'" actionId="'+a.id+'" writeOffId="'+((a.bak1==undefined||a.bak1==''||a.bak1==null)?0:a.bak1)+'" class="J_xdialogue"></b><em>'+(a.sourceStr!=undefined?a.sourceStr:"未知")+'</em></div></div></div></div></div></li>';
	}
	$(".m_xabout").html(li);
}



function getSourceTitle(source){
	var title;
	switch (source) {
	case "1":
		title="微博";
		break;
	case "2":
		title="微信";
		break;
	case "3":
		title="QQ";
		break;
	case "4":
		title="活动";
		break;
	case "5":
		title="pc网页";
		break;
	default:
		title="未知";
		break;
	}
	return title;
	
}
</script>
</html>
